<template>
    <!-- 编辑弹窗 -->
    <el-dialog v-model="store.state.storemsg.dialogVisible" title="订单信息">
        <el-form :model="store.state.storemsg.editForm">
            <el-form-item label="订单编号" :label-width="formLabelWidth">
                <el-input v-model="store.state.storemsg.editForm.id" autocomplete="off" />
            </el-form-item>
            <el-form-item label="商品编号" :label-width="formLabelWidth">
                <el-input v-model="store.state.storemsg.editForm.goodId" autocomplete="off" />
            </el-form-item>
            <el-form-item label="门店名称" :label-width="formLabelWidth">
                <el-input v-model="store.state.storemsg.editForm.shopName" autocomplete="off" />
            </el-form-item>
            <el-form-item label="下单时间" :label-width="formLabelWidth">
                <el-input v-model="store.state.storemsg.editForm.orderTime" autocomplete="off" />
            </el-form-item>
            <el-form-item label="价格" :label-width="formLabelWidth">
                <el-input v-model="store.state.storemsg.editForm.price" autocomplete="off" />
            </el-form-item>
            <el-form-item label="购买数量" :label-width="formLabelWidth">
                <el-input v-model="store.state.storemsg.editForm.buyCounts" autocomplete="off" />
            </el-form-item>
            <el-form-item label="订单状态" :label-width="formLabelWidth">
                <el-radio-group v-model="store.state.storemsg.editForm.isFinished">
                    <el-radio label="true" prop="" v-model="store.state.storemsg.editForm.isFinished"/>
                    <el-radio label="false" />
                </el-radio-group>
            </el-form-item>
        </el-form>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="handlecancel">取消</el-button>
                <el-button type="primary" @click="handelsubmit">确定</el-button>
            </span>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import { defineEmits } from 'vue'
import { useStore } from 'vuex';
import { ElMessage, } from 'element-plus'
import http from '../util/api'

const store = useStore()

const formLabelWidth = '140px'

//父组件重新获取信息
const emit = defineEmits(['getList'])

//确认修改
const handelsubmit = () => {
    http(`/order/${store.state.storemsg.editForm.id}`, 'put', store.state.storemsg.editForm).then((res: any) => {
        if (res.status === 200) {
            ElMessage({
                type: 'success',
                message: '修改成功！',
            })

            emit('getList')
        } else {
            ElMessage({
                type: 'error',
                message: '修改失败！',
            })
        }
        store.commit('changeDialog')
    })
}

//取消修改
const handlecancel = () => {
    store.commit('changeDialog')
    ElMessage({
        type: 'info',
        message: '已取消！',
    })
}

</script>
<style scoped>
.el-button--text {
    margin-right: 15px;
}

.el-select {
    width: 300px;
}

.el-input {
    width: 300px;
}

.dialog-footer button:first-child {
    margin-right: 10px;
}
</style>